/**
 * Created by admin on 2016/8/9.
 */
var assert = require('../assert');

//获取对应商品的评论
exports.getMe = function (req, res) {
    var userId = req.params.userId;
    if (!userId){
        res.send(assert.response_sms(101, '用户ID有误'));
        return
    }
    //通过用户ID先获取用户的基本信息
    Parse.Cloud.useMasterKey();
    var User = new Parse.Query('_User');
    User.get(userId).then(function (user) {
        //获取基本信息
        var results = {};
        results.nickname = user.get('nickname');
        results.avatar = user.get('avatar');
        //获取用的订单信息,分类别获取订单数量
        var orderStatus = {
            waitPay:0,
            waitSend:0,
            waitAccept:0,
            waitComment:0,
            refund:0
        };
        var query = new Parse.Query('OPOrder');
        query.equalTo('user',user);
        query.select('status');
        query.find().then(function (resultsAll) {
            if(resultsAll.length > 0){
                resultsAll.map(function (obj,index) {
                    var orderStat = obj.get('status');
                    switch (orderStat){
                        case 0:
                            orderStatus.waitPay += 1;
                            break;
                        case 1:
                            orderStatus.waitSend += 1;
                            break;
                        case 2:
                            orderStatus.waitAccept += 1;
                            break;
                        case 3:
                            orderStatus.waitComment += 1;
                            break;
                        default :
                            break;
                    }
                })
            }
            results.orderStatus = orderStatus;
            res.send(assert.response_sms(200, '获取成功',results));
        }, function (err) {
            res.send(assert.response_sms(103, '查询失败'));
        })
    }, function (error,err) {
        res.send(assert.response_sms(104, '没有该用户的信息'));
    });

};
